package com.huluobo.jetpackkotlindemo2006a.lifecycle

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.huluobo.jetpackkotlindemo2006a.R

/**
 * Created by lc on 2023/2/10.
 */
class TipDialog(context: Context) : Dialog(context), LifecycleObserver {

    init {
        if (context is AppCompatActivity) {
            context.lifecycle.addObserver(this)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    private fun onDestroy() {
        if (isShowing) {
            dismiss()
        }
    }
}